package com.yd.app.service.mobile.goodsService;

import com.yd.app.mapper.GoodsMapper;
import com.yd.app.mapper.GoodsWeightMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.Goods;
import com.yd.domain.business.GoodsWeight;
import com.yd.domain.business.Pic;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.GoodsSearchParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zg
 * @create 2018-03-07 17:44
 * @des 商品
 **/
@Service
public class MGoodsService extends BaseService {

    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    GoodsWeightMapper goodsWeightMapper;
    /**
     * 查询商品
     * @param goodsId
     * @return
     */
    public Goods getGoodsById(String goodsId) {
        Goods goods=goodsMapper.getGoodsById(goodsId);
        List<GoodsWeight>goodsWeightList=goodsWeightMapper.getGoodsWeight(goodsId);
        if(goodsWeightList!=null){
            goods.setGoodsWeightList(goodsWeightList);
        }
        return goods;
    }

    /**
     * 查询商品列表
     * @param param
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public PageModel goodsList(GoodsSearchParam param, int pageIndex, int pageSize) {
        PageModel pm=new PageModel();
        param.setCheckStatus("1");
        param.setStatus("1");
        List<Goods> returnList=goodsMapper.getGoodsList(param,getStartRow(pageIndex,pageSize),pageSize);
        int count=0;
        if(pageIndex==1){
            //查询总条数
            count=goodsMapper.getGoodsListCount(param);
        }
        pm.setCount(count);
        pm.setList(returnList);
        return  pm;
    }
    public PageModel goodsListSH(GoodsSearchParam param, int startIndex, int pageSize) {
        PageModel pm=new PageModel();
        param.setCheckStatus("1");
        param.setStatus("1");
        List<Goods> returnList=goodsMapper.getGoodsList(param,startIndex,pageSize);
        pm.setList(returnList);
        return  pm;
    }
    public   List<Goods>  goodsListSH_init(GoodsSearchParam param, int startIndex, int pageSize) {
        param.setCheckStatus("1");
        param.setStatus("1");
        List<Goods> returnList=goodsMapper.getGoodsList(param,startIndex,pageSize);
        return  returnList;
    }
    /**
     * @Author: zy
     * @Desc:获取所有图片
     * @Date:  2018/4/3
     * @Param
     */
    public List<Pic> getAllPic(String goodId){
        List<Pic> list=new ArrayList<>();
        list=goodsMapper.getAllPic(goodId);
        return list;
    }

}
